home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Gamer (Italian) 28
/
PC Gamer IT CD 28 1-2.iso
/
MSPRING
/
INSTALL
/
16BIT
/
DISK1.Z
/
MDMSTAT.EXP
< prev
next >
Wrap
Text File
|
1995-01-09
|
11KB
|
405 lines
#include "pp_api.h" /* #### AutoPinPointed #### */
/*
* TCP/Entry
* TCP/IP Services for Microsoft Windows 3.1
*
* Copyright 1995 by Network TeleSystems, Inc.
* All rights reserved.
*
* mdmstat.exp
* SLIP/PPP Dialer Modem Status Example Source.
* NOT guaranteed to compile.
*/
#include <windows.h>
#include <windowsx.h>
#include "ntsms.h"
/* ------------------------------------------------------------------ *
* Globals. *
* ------------------------------------------------------------------ */
static BOOL fEverConnected = FALSE;
static HBITMAP hBitMapModemStatus = NULL;
static HINSTANCE hInst = NULL;
static HWND hWndMain = NULL;
static HCL hCl = NULL;
#define WM_USER_MODEMSTATUS (WM_USER+1)
/* ------------------------------------------------------------------ *
* Modem Status Lights. *
* ------------------------------------------------------------------ */
#define MODEMSTATUS_WANT (MODEMSTATUS_RTS | MODEMSTATUS_DCD | \
MODEMSTATUS_CTS | MODEMSTATUS_RI | \
MODEMSTATUS_TX | MODEMSTATUS_RX | \
MODEMSTATUS_DIALERACTIVE)
#define MSLIGHT_HEIGHT 2
#define MSLIGHT_WIDTH 9
#define MSLIGHT_TOP 6
#define MSLIGHT_INTERVAL 16
#define MSLIGHT_RI 6
#define MSLIGHT_CD (MSLIGHT_RI+MSLIGHT_INTERVAL)
#define MSLIGHT_RS (MSLIGHT_CD+MSLIGHT_INTERVAL)
#define MSLIGHT_CS (MSLIGHT_RS+MSLIGHT_INTERVAL)
#define MSLIGHT_RD (MSLIGHT_CS+MSLIGHT_INTERVAL)
#define MSLIGHT_SD (MSLIGHT_RD+MSLIGHT_INTERVAL)
static UMODEMSTATUS uModemStatus = MODEMSTATUS_NULL;
static UMODEMSTATUS uLastModemStatus = MODEMSTATUS_NULL;
static COLORREF OnColor;
static COLORREF OffColor;
static HBRUSH hBrushOn = NULL;
static HBRUSH hBrushOff = NULL;
/* ================================================================== *
* Strings. *
* ================================================================== */
static char szOFFCOLORSTR[] = {"192,192,192"};
static char szONCOLORSTR[] = {"255,0,0"};
/* ------------------------------------------------------------------ *
* Forwards. *
* ------------------------------------------------------------------ */
LRESULT
CALLBACK ModemStatusWndProc(
HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam
);
/* ================================================================== *
* Initialization *
* ================================================================== */
/* ------------------------------------------------------------------ *
* AppFinalize - perform one time finalization. * *
* ------------------------------------------------------------------ */
static
void AppFinalize(
void
)
{
if (hWndMain != NULL)
RegisterModemStatusMessage(hWndMain, 0, MODEMSTATUS_NULL);
hWndMain = NULL;
if (hBitMapModemStatus != NULL)
DeleteObject(hBitMapModemStatus);
if (hBrushOn != NULL);
DeleteObject(hBrushOn);
if (hBrushOff != NULL);
DeleteObject(hBrushOff);
UnregisterClass((LPSTR)szMainClassName, hInst);
} /* AppFinalize */
/* ------------------------------------------------------------------ *
* AppInitialize - Register window classes and perform other one *
* time initialization. *
* ------------------------------------------------------------------ */
static
BOOL AppInitialize(
char *Session,
int cmdShow
)
{
BITMAP bm;
char *szPtr;
char szVersion[32];
HVERS hVers;
RECT rectMain;
WNDCLASS WndClass;
#ifndef WIN32
if ((GetWinFlags()&WF_PMODE) == 0)
{
return FALSE;
}
#endif
hBitMapModemStatus = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_MDMSTAT));
if (hBitMapModemStatus == NULL)
{
return FALSE;
}
GetObject (hBitMapModemStatus, sizeof (BITMAP), (LPSTR) &bm);
ColorStrToCOLORREF((COLORREF*)&(OnColor), szONCOLORSTR);
ColorStrToCOLORREF((COLORREF*)&(OffColor), szOFFCOLORSTR);
hBrushOn = CreateSolidBrush(OnColor);
hBrushOff = CreateSolidBrush(OffColor);
/* Register window class for main window */
memset((void*)&WndClass, 0, sizeof(WndClass));
WndClass.lpszClassName = (LPSTR)szMainClassName;
WndClass.hInstance = hInst;
WndClass.lpfnWndProc = (WNDPROC)ModemStatusWndProc;
if (!RegisterClass((LPWNDCLASS)&WndClass))
{
return FALSE;
}
/* Create the main window */
hWndMain =
CreateWindow((LPSTR)szMainClassName,
(LPSTR)szWinTitle,
WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION,
rectMain.left,
rectMain.top,
bm.bmWidth + (2 * GetSystemMetrics(SM_CXBORDER)),
bm.bmHeight + GetSystemMetrics(SM_CYCAPTION) + (GetSystemMetrics(SM_CYBORDER)),
(HWND)0,
(HMENU)0,
(HINSTANCE)hInst,
(LPVOID)NULL);
if (hWndMain == NULL)
{
AppFinalize();
return FALSE;
}
if (!RegisterModemStatusMessage(hWndMain, WM_USER_MODEMSTATUS, MODEMSTATUS_WANT))
{
return FALSE;
}
ShowWindow(hWndMain, SW_SHOWNOACTIVATE);
UpdateWindow(hWndMain);
return TRUE; /* Initialization succeeded */
} /* AppInitialize */
/* ------------------------------------------------------------------ *
* WinMain - The Main Function. *
* ------------------------------------------------------------------ */
int PASCAL WinMain(
HINSTANCE hInstance,
HANDLE hPrevInstance,
LPSTR lpszCmdLine,
int cmdShow
)
{
HWND hWndFirst;
MSG msg;
/* see if app is already running. */
if ((hWndFirst = FindWindow(szMainClassName, NULL)) != NULL)
{
return FALSE;
}
/* Save Instance Handle */
hInst = hInstance;
if (!AppInitialize(lpszCmdLine, cmdShow))
{
/* failed to initialize */
AppFinalize();
return FALSE;
}
while (GetMessage((LPMSG)&msg, (HWND)0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
AppFinalize();
return (int)msg.wParam;
} /* WinMain */
/* ------------------------------------------------------------------ *
* DrawBitmap - from Programming Windows 3.1, page 631. *
* ------------------------------------------------------------------ */
static
void DrawBitmap(
HDC hdc,
HBITMAP hBitmap,
short xStart,
short yStart
)
{
BITMAP bm;
HDC hdcMem;
POINT ptSize, ptOrg;
hdcMem = CreateCompatibleDC (hdc);
SelectObject (hdcMem, hBitmap);
SetMapMode (hdcMem, GetMapMode (hdc));
GetObject (hBitmap, sizeof (BITMAP), (LPSTR) &bm);
ptSize.x = bm.bmWidth;
ptSize.y = bm.bmHeight;
DPtoLP (hdc, &ptSize, 1);
ptOrg.x = 0;
ptOrg.y = 0;
DPtoLP (hdcMem, &ptOrg, 1);
BitBlt (hdc, xStart, yStart, ptSize.x, ptSize.y,
hdcMem, ptOrg.x, ptOrg.y, SRCCOPY);
DeleteDC (hdcMem);
} /* DrawBitmap */
/* ------------------------------------------------------------------ *
* InvalidateModemStatusLight *
* ------------------------------------------------------------------ */
static
void InvalidateModemStatusLight(
UINT uLeft
)
{
RECT rect;
rect.top = MSLIGHT_TOP;
rect.bottom = MSLIGHT_TOP + MSLIGHT_HEIGHT;
rect.left = uLeft;
rect.right = uLeft + MSLIGHT_WIDTH;
InvalidateRect(hWndMain, &rect, FALSE /* fErase */);
} /* InvalidateModemStatusLight */
/* ------------------------------------------------------------------ *
* SetModemStatusLight *
* ------------------------------------------------------------------ */
static
void SetModemStatusLight(
HDC hDC,
UINT uLeft,
BOOL fState
)
{
RECT rect;
rect.top = MSLIGHT_TOP;
rect.bottom = MSLIGHT_TOP + MSLIGHT_HEIGHT;
rect.left = uLeft;
rect.right = uLeft + MSLIGHT_WIDTH;
if (fState)
FillRect(hDC, &rect, hBrushOn);
else
FillRect(hDC, &rect, hBrushOff);
} /* SetModemStatusLight */
/* ------------------------------------------------------------------ *
* ModemStatusWndProc - Window function for 'ModemStatus' window *
* ------------------------------------------------------------------ */
LRESULT
CALLBACK ModemStatusWndProc(
HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam
)
{
HDC hDC;
PAINTSTRUCT ps;
switch (message)
{
case WM_CLOSE:
WriteAppSectionToINI();
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
hDC = BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
if (ps.fErase)
{
DrawBitmap(hDC, hBitMapModemStatus, 0, 0);
uLastModemStatus = MODEMSTATUS_NULL;
}
if ((uLastModemStatus & MODEMSTATUS_RI) !=
(uModemStatus & MODEMSTATUS_RI))
SetModemStatusLight(hDC, MSLIGHT_RI, ((uModemStatus & MODEMSTATUS_RI) != 0));
if ((uLastModemStatus & MODEMSTATUS_DCD) !=
(uModemStatus & MODEMSTATUS_DCD))
SetModemStatusLight(hDC, MSLIGHT_CD, ((uModemStatus & MODEMSTATUS_DCD) != 0));
if ((uLastModemStatus & MODEMSTATUS_RTS) !=
(uModemStatus & MODEMSTATUS_RTS))
SetModemStatusLight(hDC, MSLIGHT_RS, ((uModemStatus & MODEMSTATUS_RTS) != 0));
if ((uLastModemStatus & MODEMSTATUS_CTS) !=
(uModemStatus & MODEMSTATUS_CTS))
SetModemStatusLight(hDC, MSLIGHT_CS, ((uModemStatus & MODEMSTATUS_CTS) != 0));
if ((uLastModemStatus & MODEMSTATUS_RX) !=
(uModemStatus & MODEMSTATUS_RX))
SetModemStatusLight(hDC, MSLIGHT_RD, ((uModemStatus & MODEMSTATUS_RX) != 0));
if ((uLastModemStatus & MODEMSTATUS_TX) !=
(uModemStatus & MODEMSTATUS_TX))
SetModemStatusLight(hDC, MSLIGHT_SD, ((uModemStatus & MODEMSTATUS_TX) != 0));
uLastModemStatus = uModemStatus;
EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
break;
case WM_USER_MODEMSTATUS:
uModemStatus = wParam;
if ((uLastModemStatus & MODEMSTATUS_RI) !=
(uModemStatus & MODEMSTATUS_RI))
InvalidateModemStatusLight(MSLIGHT_RI);
if ((uLastModemStatus & MODEMSTATUS_DCD) !=
(uModemStatus & MODEMSTATUS_DCD))
InvalidateModemStatusLight(MSLIGHT_CD);
if ((uLastModemStatus & MODEMSTATUS_RTS) !=
(uModemStatus & MODEMSTATUS_RTS))
InvalidateModemStatusLight(MSLIGHT_RS);
if ((uLastModemStatus & MODEMSTATUS_CTS) !=
(uModemStatus & MODEMSTATUS_CTS))
InvalidateModemStatusLight(MSLIGHT_CS);
if ((uLastModemStatus & MODEMSTATUS_RX) !=
(uModemStatus & MODEMSTATUS_RX))
InvalidateModemStatusLight(MSLIGHT_RD);
if ((uLastModemStatus & MODEMSTATUS_TX) !=
(uModemStatus & MODEMSTATUS_TX))
InvalidateModemStatusLight(MSLIGHT_SD);
UpdateWindow(hWndMain);
if (uModemStatus & MODEMSTATUS_DCD)
fEverConnected = TRUE;
if (fEverConnected)
if ((uModemStatus & (MODEMSTATUS_DCD | MODEMSTATUS_DIALERACTIVE)) == 0)
{
/* cd gone and dialer inactive. Stop. */
PostMessage(hWnd, WM_CLOSE, 0, 0L);
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0L;
} /* ModemStatusWndProc */